/*********************************************
 * Purpose:  Contains common data structures *
 *********************************************/

#ifndef __SDL_POINT_HPP
#define __SDL_POINT_HPP

struct sdlPoint
{
    int x, y;

    sdlPoint()
    {
        x = 0;
        y = 0;
    }

    sdlPoint( int anX, int aY )
    {
        x = anX;
        y = aY;
    }
};

class sdlRect : public SDL_Rect
{
public:
    sdlRect()
    {
        x = 0;
        y = 0;
        w = 0;
        h = 0;
    }

    sdlRect(const sdlRect &o)
    {
        x = o.x;
        y = o.y;
        w = o.w;
        h = o.h;
    }

    bool isCollision( const SDL_Rect &other ) const
    {
        bool result = true;
        Sint16 left1,  left2,
               top1,   top2,
               right1, right2,
               bot1,   bot2;

        left1  = x;
        top1   = y;
        right1 = x+w;
        bot1   = y+h;
        left2  = other.x;
        top2   = other.y;
        right2 = other.x+other.w;
        bot2   = other.y+other.h;

        if( bot1 < top2 )
            result = false;
        else if( top1 > bot2 )
            result = false;
        else if( right1 < left2 )
            result = false;
        else if( left1 > right2 )
            result = false;

        return result;
    }

    sdlRect & operator=( const sdlRect &o )
    {
        if( this != &o )
        {
            x = o.x;
            y = o.y;
            w = o.w;
            h = o.h;
        }
        return *this;
    }

    sdlRect & operator=( const SDL_Rect &o )
    {
        if( this != &o )
        {
            x = o.x;
            y = o.y;
            w = o.w;
            h = o.h;
        }
        return *this;
    }
};

class sdlSize
{
private:
    int theWidth, theHeight;

public:
    sdlSize()
    {
        theWidth  = -1;
        theHeight = -1;
    }

    sdlSize( int aWidth, int aHeight )
    {
        theWidth  = aWidth;
        theHeight = aHeight;
    }

    // decreases size by the width and height of aSize
    void decBy( const sdlSize &aSize )
    {
        theWidth  -= aSize.getWidth();
        theHeight -= aSize.getHeight();
    }

    // decreases width by dx and height by dy
    void decBy( const int dx, const int dy )
    {
        theWidth  -= dx;
        theHeight -= dy;
    }

    // decreases both width and height by d
    void decBy( const int d )
    {
        theWidth  -= d;
        theHeight -= d;
    }

    // returns true if neither the width nor height are equal to -1
    bool isFullySpecified() const
    {
        return (theWidth != -1 && theHeight != -1) ? true : false;
    }

    //returns the width attribute
    inline int getWidth() const
    {
        return theWidth;
    }

    // returns the height attribute
    inline int getHeight() const
    {
        return theHeight;
    }

    // increases size by the width and height of aSize
    void incBy( const sdlSize &aSize )
    {
        theWidth  += aSize.getWidth();
        theHeight += aSize.getHeight();
    }

    // increases width by dx and height by dy
    void incBy( const int dx, const int dy )
    {
        theWidth  += dx;
        theHeight += dy;
    }

    // increases both width and height by d
    void incBy( const int d )
    {
        theWidth  += d;
        theHeight += d;
    }

    // sets the width and height attributes
    void set( int aWidth, int aHeight )
    {
        theWidth  = aWidth;
        theHeight = aHeight;
    }

    // sets the height attribute
    void setHeight( int aHeight )
    {
        theHeight = aHeight;
    }

    // sets the width attribute
    void setWidth( int aWidth )
    {
        theWidth = aWidth;
    }

    // assignment operator
    sdlSize& operator=( const sdlSize &sz )
    {
        theWidth  = sz.getWidth();
        theHeight = sz.getHeight();
        return *this;
    }

    bool operator==( const sdlSize &sz ) const
    {
        return ((theWidth == sz.getWidth()) && (theHeight == sz.getHeight())) ? true : false;
    }
};

#endif //__SDL_POINT_HPP
